package com.ljx.itbbs.server.article.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljx.itbbs.server.article.domain.entity.ArticleDraftEntity;
import com.ljx.itbbs.server.article.domain.vo.req.ArticleListReq;
import com.ljx.itbbs.server.article.mapper.ArticleDraftMapper;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class ArticleDraftDao extends ServiceImpl<ArticleDraftMapper, ArticleDraftEntity> {

    public IPage<ArticleDraftEntity> getArticleList(ArticleListReq req, Long userId) {
        IPage<ArticleDraftEntity> page = new Page<>(req.getCurrPage(), req.getPageSize());
        LambdaQueryWrapper<ArticleDraftEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ArticleDraftEntity::getUid, userId);
        if (Objects.nonNull(req.getPlateId())){
            queryWrapper.eq(ArticleDraftEntity::getPlateId, req.getPlateId());
        }
        if (Objects.nonNull(req.getCategoryId())){
            queryWrapper.eq(ArticleDraftEntity::getCategoryId, req.getCategoryId());
        }
        return this.baseMapper.selectPage(page, queryWrapper);
    }
}
